package demo.game.chess.client.ui;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Image;

import demo.game.chess.common.AbstractChessPiece;

public class ChessPieceUI extends Image {

	private final ChessBoardUI boardUI;

	private final AbstractChessPiece piece;

	public ChessPieceUI(final ChessBoardUI boardUI,
			final AbstractChessPiece piece) {
		this.boardUI = boardUI;
		this.piece = piece;

		this.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(final ClickEvent event) {

				boardUI.getMoveValidator().setDndMode(false);
				boardUI.getMoveValidator().selectPiece(ChessPieceUI.this);

			}
		});
	}

	public ChessCellUI getCellUI() {
		return this.boardUI.locate(this);
	}

	public AbstractChessPiece getPiece() {
		return this.piece;
	}

	@Override
	public String toString() {
		return this.piece.toString();
	}

}
